﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace Team4Mock.DAO
{
    public class TeamDAO
    {
        Helper h=new Helper();
        public DataTable GetdataByIDTeam(int idTeam)
        {
            SqlParameter[]p=new SqlParameter[1];
            p[0]=new SqlParameter("idTeam",idTeam);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Team_GetdataByIDTeam", p);
        }
        public DataTable GetdataByIDDepart(int idDepart)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("idDepart", idDepart);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Team_GetdataByDepartment", p);
        }
        public void Del(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Team_Del", p);
        }
        public DataTable CopyOrg(int idorg)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@idorg", idorg);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Team_CopyOrg", p);
        }
        public DataTable CopyDirec(int iddepart)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@iddepart", iddepart);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Team_CopyDepart", p);
        }
        public void Insert(string name, string shortdes, int contact, string add1, string add2, string add3, string post, string town, string county, string country, string bus, string sic, string full, string phone, string fax, string web, string charity, string company, int iddepart, int active)
        {
            SqlParameter[] p = new SqlParameter[20];
            p[0] = new SqlParameter("@name", name);
            p[0].SqlDbType = SqlDbType.NVarChar;
            p[1] = new SqlParameter("@short", shortdes);
            p[1].SqlDbType = SqlDbType.NVarChar;
            p[2] = new SqlParameter("@contact", contact);
            p[2].SqlDbType = SqlDbType.Int;
            p[3] = new SqlParameter("@add1", add1);
            p[3].SqlDbType = SqlDbType.NVarChar;
            p[4] = new SqlParameter("@add2", add2);
            p[4].SqlDbType = SqlDbType.NVarChar;
            p[5] = new SqlParameter("@add3", add3);
            p[5].SqlDbType = SqlDbType.NVarChar;
            p[6] = new SqlParameter("@post", post);
            p[6].SqlDbType = SqlDbType.VarChar;
            p[7] = new SqlParameter("@town", town);
            p[7].SqlDbType = SqlDbType.NVarChar;
            p[8] = new SqlParameter("@county", county);
            p[8].SqlDbType = SqlDbType.NVarChar;
            p[9] = new SqlParameter("@country", country);
            p[9].SqlDbType = SqlDbType.NVarChar;
            p[10] = new SqlParameter("@bus", bus);
            p[10].SqlDbType = SqlDbType.NVarChar;
            p[11] = new SqlParameter("@sic", sic);
            p[11].SqlDbType = SqlDbType.VarChar;
            p[12] = new SqlParameter("@full", full);
            p[12].SqlDbType = SqlDbType.NVarChar;
            p[13] = new SqlParameter("@phone", phone);
            p[13].SqlDbType = SqlDbType.VarChar;
            p[14] = new SqlParameter("@fax", fax);
            p[14].SqlDbType = SqlDbType.VarChar;

            p[15] = new SqlParameter("@web", web);
            p[15].SqlDbType = SqlDbType.VarChar;
            p[16] = new SqlParameter("@charity", charity);
            p[16].SqlDbType = SqlDbType.VarChar;
            p[17] = new SqlParameter("@company", company);
            p[17].SqlDbType = SqlDbType.VarChar;
            p[18] = new SqlParameter("@iddepart", iddepart);
            p[18].SqlDbType = SqlDbType.Int;
            p[19] = new SqlParameter("@active", active);
            p[19].SqlDbType = SqlDbType.Int;

            h.ExecuteNonQuerry("Team_Insert", p);
        }
        public void Update(string name, string shortdes, int contact, string add1, string add2, string add3, string post, string town, string county, string country, string bus, string sic, string full, string phone, string fax, string web, string charity, string company, int active, int id)
        {
            SqlParameter[] p = new SqlParameter[20];
            p[0] = new SqlParameter("@name", name);
            p[0].SqlDbType = SqlDbType.NVarChar;
            p[1] = new SqlParameter("@short", shortdes);
            p[1].SqlDbType = SqlDbType.NVarChar;
            p[2] = new SqlParameter("@contact", contact);
            p[2].SqlDbType = SqlDbType.Int;
            p[3] = new SqlParameter("@add1", add1);
            p[3].SqlDbType = SqlDbType.NVarChar;
            p[4] = new SqlParameter("@add2", add2);
            p[4].SqlDbType = SqlDbType.NVarChar;
            p[5] = new SqlParameter("@add3", add3);
            p[5].SqlDbType = SqlDbType.NVarChar;
            p[6] = new SqlParameter("@post", post);
            p[6].SqlDbType = SqlDbType.VarChar;
            p[7] = new SqlParameter("@town", town);
            p[7].SqlDbType = SqlDbType.NVarChar;
            p[8] = new SqlParameter("@county", county);
            p[8].SqlDbType = SqlDbType.NVarChar;
            p[9] = new SqlParameter("@country", country);
            p[9].SqlDbType = SqlDbType.NVarChar;
            p[10] = new SqlParameter("@bus", bus);
            p[10].SqlDbType = SqlDbType.NVarChar;
            p[11] = new SqlParameter("@sic", sic);
            p[11].SqlDbType = SqlDbType.VarChar;
            p[12] = new SqlParameter("@full", full);
            p[12].SqlDbType = SqlDbType.NVarChar;
            p[13] = new SqlParameter("@phone", phone);
            p[13].SqlDbType = SqlDbType.VarChar;
            p[14] = new SqlParameter("@fax", fax);
            p[14].SqlDbType = SqlDbType.VarChar;

            p[15] = new SqlParameter("@web", web);
            p[15].SqlDbType = SqlDbType.VarChar;
            p[16] = new SqlParameter("@charity", charity);
            p[16].SqlDbType = SqlDbType.VarChar;
            p[17] = new SqlParameter("@company", company);
            p[17].SqlDbType = SqlDbType.VarChar;

            p[18] = new SqlParameter("@active", active);
            p[18].SqlDbType = SqlDbType.Int;
            p[19] = new SqlParameter("@id", id);
            p[19].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Team_Update", p);
        }
    }
}